package com.atguigu.yygh.oss.controller;

import com.aliyuncs.exceptions.ClientException;
import com.atguigu.yygh.oss.service.FileService;
import com.atguigu.yygh.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/3/21 22:14
 */
@Api(tags = "aliyun oss 文件上传")
@RestController
@RequestMapping("/admin/oss/file")
public class FileUploadController {
    @Autowired
    private FileService fileService;

    @ApiOperation(value = "文件上传")
    @PostMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile file) throws ClientException, IOException {
        String uploadUrl =fileService.upload(file);
        return R.ok().data("url", uploadUrl).message("上传成功");
    }
}
